#pragma once

#include <iostream>
const int defaultfd = -1;
int gbacklog = 8;

#define Conv(v) (struct sockaddr *)(v)
#define Die(n)   \
    do           \
    {            \
        exit(n); \
    } while (0)

enum 
{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR,
    SENDTO_ERR,
    RECV_ERR
};


bool ParseOneLine(std::string& request_str, std::string* req_line, const std::string& Sep)
{
    auto pos = request_str.find(Sep);
    if(pos == std::string::npos)
    {
        return false;
    }
    *req_line = request_str.substr(0, pos);
    request_str.erase(0, pos + Sep.size());
    return true;
}
bool SplitString(const std::string &header, const std::string &sep, std::string *key, std::string *value)
{
    auto pos = header.find(sep);
    if (pos == std::string::npos)
        return false;
    *key = header.substr(0, pos);
    *value = header.substr(pos+sep.size());
    return true;
}